* Clear and unclear laws over time

clear all
set more off

qui include "bill-analysis/bill_setup.do"

merge 1:1 fips year using "data/lawcounts.dta"
drop if _merge == 2
drop _merge

foreach v of varlist laws_* {
	replace `v' = 0 `rng' & mi(`v')
}

eststo clear
loc m = 1

xtset fips year

foreach dv of varlist laws_neutral laws_uncertain {
	xtpoisson `dv' L.`shoot' `controls' `rng', fe vce(robust)
	qui estadd local sfix = "Yes"
    qui estadd local yfix = "Yes"
    qui estadd local trnd = "No"
    eststo m`m' , title("`dv'")
    loc m = `m' + 1

	xtpoisson `dv' shootX???leg `controls' `rng', fe vce(robust)
	qui estadd local sfix = "Yes"
	qui estadd local yfix = "Yes"
	qui estadd local trnd = "No"
	eststo m`m' , title("`dv' X Politics")
	loc m = `m' + 1
}

writemodel using "`out'/neutral_laws", ext(csv) drop(*.year) order(L.shoot shootX*)


// clear and unclear laws over time

gen int clear_laws = laws_tighten + laws_loosen + laws_neutral + laws_both + laws_uncertain

preserve
collapse (sum) laws_* `billdv' `lawdv' clear_laws `rng' , by(year)
gen int unclear_laws = `lawdv' - clear_laws
assert unclear_laws == laws_unknown

twoway connected `lawdv' unclear_laws year , aspect(0.5) ///
	m(o o) mfc(midblue white) mlc(midblue black) lc(midblue black) ///
	graphregion(c(white)) xlab(1990(3)2014) ylab(, nogrid) xtitle("Year") ///
	legend(label(1 "Total Laws") label(2 "Unclear Laws") ///
			col(1) ring(0) pos(11) region(lw(vvthin) lc(white) margin(3 0)))

cap graph export "`out'/fig/unclear_laws.png", replace width(3000)
restore

xtset fips year

// rate of unknown or neutral laws conditional on passing any law

loc opt "fe vce(robust) exposure(`lawdv')"
loc smp "`rng' & `lawdv' > 0"

foreach dv of varlist laws_unknown laws_neutral {

    xtpoisson `dv' L.`shoot' `controls' `smp', `opt'
}
exit
